CAN Gateway code example  v1.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Functions | Variables
cangw.cpp File Reference

Handling functions for CAN Gateway. More...

#include <cstring>
#include <pthread.h>
#include <unistd.h>
#include <new>
#include <hdj2534.h>
#include "cangw.hpp"

Go to the source code of this file.

Classes

struct  GwParam_s
 Definition of structure with CAN Gateway's parameters. More...
 
struct  ThreadParam_s
 Definition of structure with thread parameters. More...
 

Functions

static ErrCode_e canGwOpen ()
 Function opens CAN Gateway. More...
 
static ErrCode_e canGwClose ()
 Function closes CAN Gateway. More...
 
static ErrCode_e canGwConnectChannels ()
 Function connects CAN Gateway's channels. More...
 
static ErrCode_e canGwDisconnectChannels ()
 Function disconnects CAN Gateway's channels. More...
 
static ErrCode_e canGwSetFilters ()
 Function sets CAN Gateway's message filters. More...
 
static ErrCode_e canGwInitRcvThread (Channel_e channel)
 Function initializes receiving thread for given physical channel. More...
 
static ErrCode_e canGwUninitRcvThread (Channel_e channel)
 Function uninitializes receiving thread for given physical channel. More...
 
static void * canGwRcvThreadFunc (void *params)
 Function handles CAN Gateway's receiving threads. More...
 

Variables

static GwParam_s gwParam = {0, 0, 0, 0, 0, 0, 0, false, false}
 Structure with CAN device parameters.
 
static ThreadParam_s threadParamCh1
 Structure with thread parameters for Channel1.
 
static ThreadParam_s threadParamCh2
 Structure with thread parameters for Channel2.
 
static pthread_mutex_t gwMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex for CAN Gateway's API.
 
static RcvCb_t rcvCbCh1
 Receive callback function for Channel 1.
 
static RcvCb_t rcvCbCh2
 Receive callback function for Channel 2.
 
static J2534::PASSTHRU_MSG * rxPassThruMsgCh1 = NULL
 Pointer to receive buffer with PASSTHRU messages for Channel 1.
 
static J2534::PASSTHRU_MSG * rxPassThruMsgCh2 = NULL
 Pointer to receive buffer with PASSTHRU messages for Channel 2.
 
static const unsigned int MAX_RX_MSGS = 20
 Maximum number of messages to receive.
 
static unsigned long TX_TIMEOUT = 100
 Timeout for PassThruWriteMsgs() function.
 
static const unsigned long BAUD_VAL_125KBPS = 125000
 Value for baud rate = 125 kbps.
 
static const unsigned long BAUD_VAL_250KBPS = 250000
 Value for baud rate = 250 kbps.
 
static const unsigned long BAUD_VAL_500KBPS = 500000
 Value for baud rate = 500 kbps.
 
static const unsigned long BAUD_VAL_1MBPS = 1000000
 Value for baud rate = 1 Mbps.
 

Detailed Description

Handling functions for CAN Gateway.

Date
2014-03-07

Definition in file cangw.cpp.

Function Documentation

static ErrCode_e canGwOpen ( )
static

Function opens CAN Gateway.

Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 304 of file cangw.cpp.

References canGw::CAN_GW_ERR, canGw::CAN_GW_OK, canGwConnectChannels(), canGwSetFilters(), gwParam, and GwParam_s::idDevice.

Referenced by canGw::init().

static ErrCode_e canGwClose ( )
static

Function closes CAN Gateway.

Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 325 of file cangw.cpp.

References canGw::CAN_GW_ERR, canGw::CAN_GW_OK, canGwDisconnectChannels(), gwParam, and GwParam_s::idDevice.

Referenced by canGw::uninit().

static ErrCode_e canGwConnectChannels ( )
static

Function connects CAN Gateway's channels.

Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 345 of file cangw.cpp.

References GwParam_s::activeCh1, GwParam_s::activeCh2, GwParam_s::baudCh1, GwParam_s::baudCh2, canGw::CAN_GW_ERR, canGw::CAN_GW_OK, gwParam, GwParam_s::idCh1, GwParam_s::idCh2, and GwParam_s::idDevice.

Referenced by canGwOpen().

static ErrCode_e canGwDisconnectChannels ( )
static

Function disconnects CAN Gateway's channels.

Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 389 of file cangw.cpp.

References GwParam_s::activeCh1, GwParam_s::activeCh2, canGw::CAN_GW_ERR, canGw::CAN_GW_OK, gwParam, GwParam_s::idCh1, and GwParam_s::idCh2.

Referenced by canGwClose().

static ErrCode_e canGwSetFilters ( )
static

Function sets CAN Gateway's message filters.

Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 428 of file cangw.cpp.

References canGw::CAN_GW_ERR, canGw::CAN_GW_OK, gwParam, GwParam_s::idCh1, GwParam_s::idCh2, GwParam_s::idFilterCh1, and GwParam_s::idFilterCh2.

Referenced by canGwOpen().

static ErrCode_e canGwInitRcvThread ( Channel_e  channel)
static

Function initializes receiving thread for given physical channel.

Parameters
[in]channelCAN Gateway's physical channel
Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 479 of file cangw.cpp.

References ThreadParam_s::active, ThreadParam_s::attr, canGw::CAN_GW_ERR, canGw::CAN_GW_OK, canGwRcvThreadFunc(), canGw::CHANNEL_1, canGw::CHANNEL_2, ThreadParam_s::gwChannel, ThreadParam_s::id, threadParamCh1, and threadParamCh2.

Referenced by canGw::init().

static ErrCode_e canGwUninitRcvThread ( Channel_e  channel)
static

Function uninitializes receiving thread for given physical channel.

Parameters
[in]channelCAN Gateway's physical channel
Returns
CAN_GW_OK No error
CAN_GW_ERR An error occurred

Definition at line 533 of file cangw.cpp.

References ThreadParam_s::active, canGw::CAN_GW_ERR, canGw::CAN_GW_OK, canGw::CHANNEL_1, canGw::CHANNEL_2, ThreadParam_s::id, threadParamCh1, and threadParamCh2.

Referenced by canGw::uninit().

static void * canGwRcvThreadFunc ( void *  params)
static

Function handles CAN Gateway's receiving threads.

Parameters
[in]paramsPointer to structure ThreadParam_s with thread parameters
Returns
Pointer to status of the thread - always NULL

Definition at line 568 of file cangw.cpp.

References canGw::CHANNEL_1, canGw::CHANNEL_2, gwMutex, gwParam, GwParam_s::idCh1, GwParam_s::idCh2, MAX_RX_MSGS, rcvCbCh1, rcvCbCh2, rxPassThruMsgCh1, and rxPassThruMsgCh2.

Referenced by canGwInitRcvThread().